from django.db import models
from datetime import datetime


# Create your models here.

# 用户信息表
class Student(models.Model):
    id = models.IntegerField(auto_created=True, primary_key=True)
    name = models.CharField(max_length=100)
    age = models.CharField(max_length=100)
    sex = models.CharField(max_length=10)
    phone = models.CharField(max_length=100)
    password = models.CharField(max_length=100)
    create_time = models.DateField(max_length=100, verbose_name='注册日期', default=datetime.now())
    is_graduate = models.BooleanField(null=False, default=False, verbose_name='是否毕业')
    end_time = models.DateField(max_length=100, verbose_name='毕业日期')
    image = models.CharField(max_length=100,
                             default="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png")


#  教练表
class Coach_info(models.Model):
    coach_id = models.IntegerField(auto_created=True, primary_key=True)
    coach_name = models.CharField(max_length=100)
    coach_phone = models.CharField(max_length=100)
    image = models.CharField(max_length=100,
                             default="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png")


# 考试科目表
class Subject(models.Model):
    subject_id = models.IntegerField(primary_key=True, auto_created=True, verbose_name='科目id')
    subject_name = models.CharField(max_length=100, verbose_name='科目名称科一/科二/科三/科四')
    subject_detail = models.CharField(max_length=100, verbose_name='科目描述说明')


# 车辆信息表
class Car_info(models.Model):
    car_id = models.IntegerField(auto_created=True, primary_key=True, verbose_name='车辆id')
    car_pai = models.CharField(max_length=100, verbose_name='车牌号')
    car_model = models.CharField(max_length=100, verbose_name='车辆型号')
    car_state = models.BooleanField(null=False, default=True, verbose_name='车辆状态，使用中/空闲中')
    coa = models.ForeignKey(Coach_info, on_delete=models.SET_NULL, null=True, verbose_name='外键')
    car_notes = models.CharField(max_length=100, verbose_name='车辆备注信息')
    image = models.CharField(max_length=100,
                             default="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png")


# 学员预约训练表
class Student_train(models.Model):
    train_id = models.IntegerField(auto_created=True, primary_key=True, verbose_name='预约id')
    student = models.ForeignKey(Student, on_delete=models.SET_NULL, null=True, verbose_name='关联学员信息')
    test = models.ForeignKey(Subject, on_delete=models.SET_NULL, null=True, verbose_name='关联考试科目')
    car = models.ForeignKey(Car_info, on_delete=models.SET_NULL, null=True, verbose_name='关联车辆信息')
    ground_id = models.CharField(max_length=100, verbose_name='预约场地')
    session = models.DateField(max_length=100, verbose_name='预约时间段')
    is_status = models.BooleanField(null=True, default=False, verbose_name='是否预约')


#  学员训练记录表，关联教练表 和 用户表
class Student_teach(models.Model):
    record_id = models.IntegerField(auto_created=True, primary_key=True, verbose_name='记录id')
    stu = models.ForeignKey(Student, on_delete=models.SET_NULL, null=True, verbose_name='关联学员信息')
    coa = models.ForeignKey(Coach_info, on_delete=models.SET_NULL, null=True, verbose_name='关联教练信息')
    car = models.ForeignKey(Car_info, on_delete=models.SET_NULL, null=True, verbose_name='关联车量信息')
    test = models.ForeignKey(Subject, on_delete=models.SET_NULL, null=True, verbose_name='关联考试科目')
    ground = models.CharField(max_length=100, verbose_name='训练场地')
    train_time = models.DateField(max_length=100, verbose_name='训练时间', default=datetime.now())
    comment_student = models.CharField(max_length=100, verbose_name='学员评论', null=True)
    comment_coach = models.CharField(max_length=100, verbose_name='教练评论', null=True)
    train = models.ForeignKey(Student_train, on_delete=models.SET_NULL, null=True, verbose_name="关联预约训练表")


# 学员预约考试
class Student_text(models.Model):
    test_id = models.IntegerField(auto_created=True, primary_key=True, verbose_name='考试id')
    student = models.ForeignKey(Student, on_delete=models.SET_NULL, null=True, verbose_name='关联学员信息')
    subject = models.ForeignKey(Subject, on_delete=models.SET_NULL, null=True, verbose_name='关联考试科目')
    ground = models.CharField(max_length=100, verbose_name='考试场地')
    session = models.DateField(max_length=100, verbose_name='预约时间', default=datetime.now())


# 考试结果表  关联学员预约考试

class Test_result(models.Model):
    result_id = models.IntegerField(auto_created=True, primary_key=True, verbose_name='结果id')
    test = models.ForeignKey(Student_text, on_delete=models.SET_NULL, null=True, verbose_name='关联考试预约')
    session = models.DateField(max_length=100, verbose_name='实际考试时间')
    is_pass = models.BooleanField(null=False, default=True, verbose_name='是否合格通过考试')
    score = models.IntegerField(max_length=100, verbose_name='考试成绩')
